home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / NTUMIN10.ARJ / EXIST.C < prev    next >
C/C++ Source or Header  |  1992-03-12  |  2KB  |  74 lines

  1. /****************************************************************************
  2.  *
  3.  *     Program Name : EXIST.C
  4.  *
  5.  *    Written By : Eng-Huat Ong and Kian-Mong Low.
  6.  *
  7.  *    This program tests the existence of a given minterm (in array b)
  8.  *    in a given larger array, a with size of m minterms.
  9.  *
  10.  *    Returns  0  if b is present in a
  11.  *              -1  if b is not present in a
  12.  *
  13.  * --------------------------------------------------------------------------
  14.  *    Copyright (c) 1992. All Rights Reserved. Nanyang Technological
  15.  *    University.
  16.  *
  17.  *    You are free to use, copy and distribute this software and its
  18.  *    documentation providing that:
  19.  *
  20.  *        NO FEE IS CHARGED FOR USE, COPYING OR DISTRIBUTION.
  21.  *
  22.  *        IT IS NOT MODIFIED IN ANY WAY.
  23.  *
  24.  *        THE COPYRIGHT NOTICE APPEAR IN ALL COPIES.
  25.  *
  26.  *    This program is provided "AS IS" without any warranty, expressed or
  27.  *    implied, including but not limited to fitness for any particular
  28.  *    purpose.
  29.  *
  30.  *    If you find NTUMIN fast, easy, and useful, a note or comment would be
  31.  *    appreciated. Please send to:
  32.  *
  33.  *        Boon-Tiong Tan or Othman Bin Ahmad
  34.  *        School of EEE
  35.  *        Nanyang Technological University
  36.  *        Nanyang Avenue
  37.  *        Singapore 2263
  38.  *        Republic of Singapore
  39.  *
  40.  ****************************************************************************/
  41.  
  42. #include <stdio.h>
  43. #include <string.h>
  44. #include <alloc.h>                /* TURBO C ONLY */
  45.  
  46. extern unsigned long    mem2;     /* memory left */
  47.  
  48. char     exist(b, a, m)
  49.  
  50. unsigned char       *a, *b;
  51. unsigned short      m;                      /* no. of minterms in array a */
  52.  
  53. {
  54.    unsigned long    mem3;                 /* memory space left */
  55.    unsigned char    nspm;                 /* no. of storage/minterm */
  56.    unsigned short   i;                    /* no. of minterms counter */
  57.    int              test;                 /* memory compare status */
  58.  
  59.    nspm = *(a+3);                        /* no. of bytes/minterm */
  60.  
  61.    mem3 = coreleft();                    /* current memory left */
  62.    if (mem3 < mem2)                      /* get the lowest */
  63.       mem2 = mem3;
  64.  
  65.    for (i=0; i<m; i++)                   /* check with all minterms in a */
  66.       {
  67.      test = memcmp(b, (a+4+nspm*i), nspm);
  68.      if (test == 0)                          /* b present in a */
  69.         return(0);
  70.       }
  71.  
  72.    return(-1);                                   /* b not present in a */
  73. }
  74.